package nuc.soft.xsf.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import nuc.soft.xsf.model.Title;
import nuc.soft.xsf.model.TitlePaper;
import nuc.soft.xsf.service.IPaperService;
import nuc.soft.xsf.service.ITitlePaperService;
import nuc.soft.xsf.service.ITitleService;
import nuc.soft.xsf.tools.Tools;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/PaperTitleController", produces = "text/html;charset=UTF-8")
public class PaperTitleController {
	@Resource
	private ITitlePaperService titlePaperService;

	@Resource
	private ITitleService titleService;
	
	@Resource
	private IPaperService paperService;
	//后台查询试卷题目
	@RequestMapping(value = "/findByCondition.action", produces = "text/html;charset=utf-8")
	@ResponseBody
	public String findByCondition(TitlePaper titlepaper) {
		
		Map map = Tools.transBean2Map(titlepaper);	
		//同时查询试题的数量

		List<TitlePaper> list = titlePaperService.findByCondition(map);
		List<Title> titleList=new ArrayList();
		for(int i=0;i<list.size();i++){
			Title title=new Title();
			title=titleService.findById(list.get(i).getTitleId());
			//将题号传给前台(extend2为编号 没有实际意义）
	        title.setExtend2(list.get(i).getExtend1());	
			titleList.add(title);
		}
		JSONObject json = new JSONObject();
		json.put("record", titleList);
		
		return json.getString("record");
	}

}
